//
//  T1ListModel.swift
//
//  Created by eme on 2017/4/10
//  Copyright (c) . All rights reserved.
//

import Foundation
import SwiftyJSON
import ModelProtocol
import UtilCore

class T1ListModel: ModelProtocol {
    
    // MARK: Declaration for string constants to be used to decode and also serialize.
    internal let kT1ListHeightKey: String = "height"
    internal let kT1ListUrlidKey: String = "urlid"
    internal let kT1ListInternalIdentifierKey: String = "id"
    internal let kT1ListUrlTitleKey: String = "url_title"
    internal let kT1ListWidthKey: String = "width"
    internal let kT1ListPicKey: String = "pic"
    internal let kT1ListTypeKey: String = "type"
    internal let kT1ListUrlKey: String = "url"
    
    
    // MARK: 属性
    var height: Float
    var urlid: String
    var internalIdentifier: String
    var urlTitle: String
    var width: Float
    var pic: String
    var type: Int
    var url: String
  
    
    ///item的高度更具宽度计算得出
    var i_height:CGFloat{
        get{
            if self.width > 0 {
                return self.i_width*CGFloat(self.height/750) + self.img_Top_Spacing + self.img_Top_Spacing
            }else{
                /// 默认给95的高度
                return 95 + self.img_Top_Spacing + self.img_Top_Spacing
            }
            
        }
    }
    /// T1ListModel 中的 item的宽度为屏幕的宽度
    var i_width:CGFloat{
        get{
            return screen_Width
        }
    }
    
    /**
     1.这块需要说明下，以下属性使用与t1_4,t1_5用的
     img_Spacing:图片的边距
     img_InteritemSpacing:两个image 之间的距离
     */
    
    /// 图片的左右边距
    var img_Left_Spacing:CGFloat = 8.0
    /// 图片的上下边距
    var img_Top_Spacing:CGFloat = 5.0
    /// 两个image 之间的距离
    var img_InteritemSpacing:CGFloat = 9.0
    
    
    // MARK: 实现MikerSwiftJSONAble 协议， 解析json数据
    public required  init?(json: JSON) {
        height = json[kT1ListHeightKey].floatValue
        urlid = json[kT1ListUrlidKey].stringValue
        internalIdentifier = json[kT1ListInternalIdentifierKey].stringValue
        urlTitle = json[kT1ListUrlTitleKey].stringValue
        width = json[kT1ListWidthKey].floatValue
        pic = json[kT1ListPicKey].stringValue
        type = json[kT1ListTypeKey].intValue
        url = json[kT1ListUrlKey].stringValue
        
    }
    
    
    /**
     Generates description of the object in the form of a NSDictionary.
     - returns: A Key value pair containing all valid values in the object.
     */
    func dictionaryRepresentation() -> [String : AnyObject ] {
        
        var dictionary: [String : AnyObject ] = [ : ]
        
        dictionary.updateValue(height as AnyObject, forKey: kT1ListHeightKey)
        
        
        dictionary.updateValue(urlid as AnyObject, forKey: kT1ListUrlidKey)
        
        
        dictionary.updateValue(internalIdentifier as AnyObject, forKey: kT1ListInternalIdentifierKey)
        
        
        dictionary.updateValue(urlTitle as AnyObject, forKey: kT1ListUrlTitleKey)
        
        
        dictionary.updateValue(width as AnyObject, forKey: kT1ListWidthKey)
        
        
        dictionary.updateValue(pic as AnyObject, forKey: kT1ListPicKey)
        
        
        dictionary.updateValue(type as AnyObject, forKey: kT1ListTypeKey)
        
        
        dictionary.updateValue(url as AnyObject, forKey: kT1ListUrlKey)
        
        
        return dictionary
    }
    
    
}
